package homework.api03.exercises01;

import java.util.ArrayList;
import java.util.Collection;

public class CollectionDemo4 {
    public static void main(String[] args) {
       Collection c1 = new ArrayList();
        c1.add("java");
        c1.add("c++");
        c1.add(".net");
        System.out.println("c1:"+c1);

        Collection c2 = new ArrayList();
        c2.add("android");
        c2.add("ios");
        c2.add("java");
        System.out.println("c2:"+c2);

        //addAll 将参数集合中的元素添加到当前集合中
        //添加后集合若发生改变则返回true
        c1.addAll(c2);//将c2添加到几个c1中
        System.out.println("c1:"+c1);
        System.out.println("c2:"+c2);

        Collection c3 = new ArrayList();
        c3.add("c++");
        c3.add("android");
        c3.add("php");
        System.out.println("c3:"+c3);

        //containsAll 判断当前集合是否包含参数集合中的全部元素
        boolean contains = c1.containsAll(c3);
        System.out.println("是否包含:"+contains);//false

        //取交集 retainAll 从c1中取出与c3所共有的元素 c3不变
//        c1.retainAll(c3);
//        System.out.println("c1:"+c1);//c1:[c++, android]
//        System.out.println("c3:"+c3);//c3:[c++, android, php]

        //删交集 删除c1中与c3所共有的元素 c3不变
        c1.removeAll(c3);
        System.out.println("c1:"+c1);//c1:[java, .net, ios, java]
        System.out.println("c3:"+c3);//c3:[c++, android, php]









    }
}
